package com.um.jdy.app.shop.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.app.shop.entity.dto.CartChangeNumDTO;
import com.um.jdy.app.shop.entity.dto.JoinCartDTO;
import com.um.jdy.app.shop.entity.vo.CartDetailVO;
import com.um.jdy.app.shop.manager.CartManager;
import com.um.jdy.common.shop.entity.vo.GoodsVO;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 购物车
 * @author renjunwei
 * @date 2020/9/21 09:40
 */
@Api(tags = "购物车")
@Validated
@RestController
@RequestMapping("/api/v1/goods/cart/")
public class CartController {

    @Autowired
    CartManager cartManager;

    /**
     * 查询购物车
     * @return
     */
    @SaCheckLogin
    @ApiOperation("查询购物车")
    @GetMapping()
    public Response<List<CartDetailVO>> get(){
        return Response.success(cartManager.get());
    }

    /**
     * 加入购入车
     * @param dto
     * @return
     */
    @SaCheckLogin
    @ApiOperation("加入购入车")
    @PostMapping("join")
    public Response join(@Valid @RequestBody JoinCartDTO dto){
        cartManager.join(dto);
        return Response.success();
    }

    /**
     * 修改购物车数量
     * @param dto
     * @return
     */
    @SaCheckLogin
    @ApiOperation("修改购物车商品数量")
    @PostMapping("change_num")
    public Response changeNum(@Valid @RequestBody CartChangeNumDTO dto){
        cartManager.changeNum(dto);
        return Response.success();
    }

    /**
     * 移除购入车
     * @param ids
     * @return
     */
    @SaCheckLogin
    @ApiOperation("移除购入车")
    @PostMapping("delete")
    public Response delete(@RequestBody List<String> ids){
        cartManager.delete(ids);
        return Response.success();
    }

    /**
     * 查询购物车推荐商品
     * @return
     */
    @ApiOperation("查询购物车推荐商品")
    @GetMapping("recommend")
    public Response<List<GoodsVO>> getRecommendGoods(){
        return Response.success(cartManager.getRecommendGoods());
    }


}
